# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: Modulator_ER.py
  @time: 2022/5/12 14:03
  @desc:
"""

import time

from math import *
from ATS.application.LCR_App.U2722A_App import U2722A_App
from ATS.application.LASER_App.N7744C_App import N7744C_App
from ATS.util.calcu_step_util import get_points_list
from ATS.util.save_data_2_csv_util import saveData2CSV
from matplotlib import pyplot as plt
from ATS.switchdriver.LightSwitchDriver import LightSwitchDriver
import numpy as np


def Modulator_ER(heater_channel, heater_channel_voltage, heater_channel_current_range, heater_channel_limit,
                 rf1_channel, rf1_channel_voltage, rf1_channel_voltage1, rf1_channel_current_range, rf1_channel_limit,
                 rf2_channel, rf2_channel_voltage, rf2_channel_voltage1, rf2_channel_current_range, rf2_channel_limit):
    u2722_inst = U2722A_App("SMU1")
    u2722_inst.set_voltage_range(heater_channel)
    u2722_inst.set_current_range_limit(heater_channel_current_range, heater_channel_limit, heater_channel)
    u2722_inst.set_voltage(heater_channel_voltage, heater_channel)
    u2722_inst.set_voltage_range(rf1_channel)
    u2722_inst.set_current_range_limit(rf1_channel_current_range, rf1_channel_limit, rf1_channel)
    u2722_inst.set_voltage_range(rf2_channel)
    u2722_inst.set_current_range_limit(rf2_channel_current_range, rf2_channel_limit, rf2_channel)
    u2722_inst.set_voltage(rf1_channel_voltage)
    u2722_inst.set_voltage(rf2_channel_voltage)

    n7744c_app = N7744C_App("SS2")
    p1 = n7744c_app.get_power_value()
    u2722_inst.set_voltage(rf1_channel_voltage)
    u2722_inst.set_voltage(rf2_channel_voltage)
    p2 = n7744c_app.get_power_value()
    ER = float(p1) - float(p2)
    u2722_inst.output_state(0, heater_channel)
    u2722_inst.output_state(0, rf1_channel)
    u2722_inst.output_state(0, rf2_channel)
